from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-12 14:22:22.824036
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 12, Jan, 2021
Time: 14:22:26
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -44.9940
Nobs: 169.000 HQIC: -45.9844
Log likelihood: 1874.64 FPE: 5.44494e-21
AIC: -46.6608 Det(Omega_mle): 3.24561e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.461756 0.151250 3.053 0.002
L1.Burgenland 0.139621 0.077601 1.799 0.072
L1.Kärnten -0.238825 0.062990 -3.791 0.000
L1.Niederösterreich 0.122933 0.180035 0.683 0.495
L1.Oberösterreich 0.236863 0.153832 1.540 0.124
L1.Salzburg 0.187906 0.081491 2.306 0.021
L1.Steiermark 0.076300 0.111258 0.686 0.493
L1.Tirol 0.150184 0.073840 2.034 0.042
L1.Vorarlberg 0.010396 0.070496 0.147 0.883
L1.Wien -0.131245 0.149519 -0.878 0.380
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.532047 0.194512 2.735 0.006
L1.Burgenland 0.013898 0.099796 0.139 0.889
L1.Kärnten 0.369362 0.081007 4.560 0.000
L1.Niederösterreich 0.126532 0.231530 0.547 0.585
L1.Oberösterreich -0.175329 0.197832 -0.886 0.375
L1.Salzburg 0.177715 0.104800 1.696 0.090
L1.Steiermark 0.237758 0.143080 1.662 0.097
L1.Tirol 0.143096 0.094960 1.507 0.132
L1.Vorarlberg 0.187348 0.090660 2.066 0.039
L1.Wien -0.597079 0.192285 -3.105 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.301278 0.067012 4.496 0.000
L1.Burgenland 0.105989 0.034381 3.083 0.002
L1.Kärnten -0.024100 0.027908 -0.864 0.388
L1.Niederösterreich 0.063769 0.079765 0.799 0.424
L1.Oberösterreich 0.284579 0.068155 4.175 0.000
L1.Salzburg -0.001200 0.036105 -0.033 0.973
L1.Steiermark -0.022588 0.049293 -0.458 0.647
L1.Tirol 0.097179 0.032715 2.970 0.003
L1.Vorarlberg 0.127045 0.031233 4.068 0.000
L1.Wien 0.074218 0.066244 1.120 0.263
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.214093 0.078838 2.716 0.007
L1.Burgenland -0.006479 0.040449 -0.160 0.873
L1.Kärnten 0.023411 0.032833 0.713 0.476
L1.Niederösterreich 0.029886 0.093842 0.318 0.750
L1.Oberösterreich 0.391692 0.080184 4.885 0.000
L1.Salzburg 0.093866 0.042477 2.210 0.027
L1.Steiermark 0.181048 0.057992 3.122 0.002
L1.Tirol 0.041193 0.038489 1.070 0.285
L1.Vorarlberg 0.100548 0.036746 2.736 0.006
L1.Wien -0.071048 0.077936 -0.912 0.362
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.579308 0.157521 3.678 0.000
L1.Burgenland 0.077348 0.080818 0.957 0.339
L1.Kärnten 0.002245 0.065602 0.034 0.973
L1.Niederösterreich -0.028623 0.187499 -0.153 0.879
L1.Oberösterreich 0.136402 0.160210 0.851 0.395
L1.Salzburg 0.050241 0.084870 0.592 0.554
L1.Steiermark 0.110096 0.115870 0.950 0.342
L1.Tirol 0.220027 0.076902 2.861 0.004
L1.Vorarlberg 0.012018 0.073419 0.164 0.870
L1.Wien -0.142940 0.155718 -0.918 0.359
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170511 0.111793 1.525 0.127
L1.Burgenland -0.023111 0.057356 -0.403 0.687
L1.Kärnten -0.012751 0.046558 -0.274 0.784
L1.Niederösterreich 0.175767 0.133069 1.321 0.187
L1.Oberösterreich 0.379691 0.113701 3.339 0.001
L1.Salzburg -0.033144 0.060232 -0.550 0.582
L1.Steiermark -0.048851 0.082233 -0.594 0.552
L1.Tirol 0.195587 0.054577 3.584 0.000
L1.Vorarlberg 0.046956 0.052106 0.901 0.367
L1.Wien 0.157361 0.110513 1.424 0.154
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.228057 0.140903 1.619 0.106
L1.Burgenland 0.064342 0.072292 0.890 0.373
L1.Kärnten -0.048801 0.058681 -0.832 0.406
L1.Niederösterreich -0.031883 0.167719 -0.190 0.849
L1.Oberösterreich -0.090829 0.143308 -0.634 0.526
L1.Salzburg 0.022645 0.075917 0.298 0.765
L1.Steiermark 0.370299 0.103646 3.573 0.000
L1.Tirol 0.514441 0.068789 7.479 0.000
L1.Vorarlberg 0.194682 0.065674 2.964 0.003
L1.Wien -0.220760 0.139290 -1.585 0.113
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109881 0.165502 0.664 0.507
L1.Burgenland 0.015178 0.084913 0.179 0.858
L1.Kärnten -0.105828 0.068926 -1.535 0.125
L1.Niederösterreich 0.229619 0.197000 1.166 0.244
L1.Oberösterreich 0.016998 0.168328 0.101 0.920
L1.Salzburg 0.222524 0.089170 2.495 0.013
L1.Steiermark 0.140753 0.121741 1.156 0.248
L1.Tirol 0.095037 0.080798 1.176 0.240
L1.Vorarlberg 0.017475 0.077139 0.227 0.821
L1.Wien 0.266990 0.163608 1.632 0.103
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.593595 0.089816 6.609 0.000
L1.Burgenland -0.021727 0.046081 -0.471 0.637
L1.Kärnten -0.001715 0.037405 -0.046 0.963
L1.Niederösterreich -0.014708 0.106909 -0.138 0.891
L1.Oberösterreich 0.278577 0.091349 3.050 0.002
L1.Salzburg 0.008941 0.048392 0.185 0.853
L1.Steiermark -0.000376 0.066067 -0.006 0.995
L1.Tirol 0.078668 0.043848 1.794 0.073
L1.Vorarlberg 0.170122 0.041862 4.064 0.000
L1.Wien -0.086036 0.088788 -0.969 0.333
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.147575 0.003455 0.210828 0.245705 0.064858 0.098361 -0.068951 0.159252
Kärnten 0.147575 1.000000 0.001732 0.189606 0.153305 -0.131695 0.162757 0.028862 0.304460
Niederösterreich 0.003455 0.001732 1.000000 0.285535 0.087455 0.215733 0.097070 0.063939 0.352552
Oberösterreich 0.210828 0.189606 0.285535 1.000000 0.289519 0.313517 0.088716 0.081642 0.119921
Salzburg 0.245705 0.153305 0.087455 0.289519 1.000000 0.153996 0.073910 0.075336 -0.023949
Steiermark 0.064858 -0.131695 0.215733 0.313517 0.153996 1.000000 0.098447 0.089690 -0.120982
Tirol 0.098361 0.162757 0.097070 0.088716 0.073910 0.098447 1.000000 0.151059 0.132487
Vorarlberg -0.068951 0.028862 0.063939 0.081642 0.075336 0.089690 0.151059 1.000000 0.098657
Wien 0.159252 0.304460 0.352552 0.119921 -0.023949 -0.120982 0.132487 0.098657 1.000000